home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-11 / cguide.zip / CGUIDE.DOC < prev   
Text File  |  1992-03-06  |  12KB  |  475 lines

  1. Nantucket Code Guidelines
  2.  
  3. The following guidelines are applicable to all source code.  Nantucket 
  4. reserves the right to alter submitted code, text, and comments if 
  5. necessary.
  6.  
  7. 1    Commands and Keywords
  8.  
  9. 1.1    All commands and keywords are uppercase, both in programs and 
  10. in text.  Be sure to specify the complete spelling; never use the 
  11. four-letter abbreviation:
  12.  
  13.    REPLACE CustName WITH cCustName
  14.  
  15. 1.2    When specifying a command in text or in a special element other 
  16. than code, and the command includes a clause, separate each keyword 
  17. with an ellipsis (...) and do not specify the TO clause unless it is 
  18. followed by the FILE, PRINT or SCREEN keywords:
  19.  
  20.    COPY...SDF
  21.    SET MESSAGE...CENTER
  22.    @...SAY...GET
  23.  
  24. 2    Language Syntax
  25.  
  26. 2.1    When specifying the complete syntax of a language element in 
  27. text, input items, parameters, etc. are referred to using the following 
  28. symbols:
  29.  
  30. SYMBOLS
  31.  
  32. DESCRIPTION
  33.  
  34. < >
  35. Indicates user input item
  36.  
  37. ( )
  38. Indicates function argument list
  39.  
  40. [ ]
  41. Indicates optional item or list
  42.  
  43. { }
  44. Indicates code block or literal array
  45.  
  46. | |
  47. Indicates code block argument list
  48.  
  49. -->
  50. Indicates function return value
  51.  
  52. ...
  53. Repeated elements if followed by a symbol
  54. Intervening code if followed by a keyword
  55.  
  56. ,
  57. List item separator
  58.  
  59. |
  60. Indicates two or more mutually exclusive options
  61.  
  62. @
  63. Indicates that an item must be passed by reference
  64.  
  65. *
  66. Indicates a compatibility command or function
  67.  
  68. For example:
  69.  
  70.    LEN(<cString>|<aTarget>) --> nCount
  71.  
  72. For more examples, please consult the Clipper 5.0 Reference Guide.
  73.  
  74. 2.2    Metasymbols describe the general nature of basic syntax 
  75. elements.  They are used in conjunction with the symbols listed above 
  76. to specify the syntax of a language element.  A metasymbol consists of 
  77. one or more lowercase data type designators, followed by a mixedcase 
  78. description:
  79.  
  80.    RANGE <dnLower>, <dnUpper>
  81.  
  82. In this example, dnLower and dnUpper can be either date or numeric.  
  83. Data type designators are as follows:
  84.  
  85. DESIGNATOR
  86.  
  87. DESCRIPTION
  88.  
  89. a
  90. Array
  91.  
  92. b
  93. Code block
  94.  
  95. c
  96. Character expression
  97.  
  98. d
  99. Date expression
  100.  
  101. exp
  102. Expression of any type
  103.  
  104. id
  105. Literal identifier
  106.  
  107. l
  108. Logical expression
  109.  
  110. m
  111. Memo field
  112.  
  113. n
  114. Numeric expression
  115.  
  116. o
  117. Object
  118.  
  119. x
  120. Extended expression
  121.  
  122. 3    Filenames
  123.  
  124. 3.1    The names of Clipper program and data files have the first 
  125. letter capitalized and the extensions in lowercase (e.g., MyProg.prg, 
  126. Items.dbf).  Extensions are:
  127.  
  128. .ch
  129. .dbt
  130. .frm
  131. .mem
  132. .ntx
  133. .prg
  134. .dbf
  135. .fmt
  136. .lbl
  137. .ndx
  138. .txt
  139. .vew
  140.  
  141. When referring to specific file types in text, enclose the file 
  142. extension in parentheses:  
  143.  
  144.    A program is stored in a text file with a (.prg) extension.
  145.  
  146. 3.2    Underscores should not be used anywhere in the filename.  Use 
  147. mixedcase for filenames consisting of more than one word:
  148.  
  149. USE CustNames
  150.  
  151. 3.3    The names and extensions of other files, including executable 
  152. and DOS files, are uppercase (e.g., CLIPPER.LIB, AUTOEXEC.BAT).  
  153. Extensions are:
  154.  
  155. .ASM
  156. .C
  157. .CLP
  158. .LIB
  159. .OBJ
  160. .PLL
  161.  
  162. .BAT
  163. .COM
  164. .EXE
  165. .LNK
  166. .OVL
  167.  
  168.  
  169. When referring to specific file types in text, use the appropriate 
  170. extension, including the period:
  171.  
  172.    Clipper compiles a set of (.prg) files into one .OBJ file.
  173.  
  174. 3.4    Alias names follow the same conventions as filenames.
  175.  
  176. 4    Fieldnames
  177.  
  178. 4.1    Capitalize the first letter of fieldnames:
  179.  
  180.    @ 10,10 SAY Branch
  181.  
  182. 4.2    Do not use leading underscores: these are used for Clipper 
  183. internal variable and function names.  Underscores should not be used 
  184. anywhere in the fieldname.  Use mixedcase for fieldnames consisting of 
  185. more than one word:
  186.  
  187.    ? TotalSum, NumOfLines
  188.  
  189. 4.3    Always explicitly reference fieldnames, either by using the 
  190. FIELD declaration or by preceding the fieldname with the file alias:
  191.  
  192.    FIELD CustName            
  193.    OR    
  194.    @ 10,10 SAY CustFile->CustName
  195.  
  196. @ 10,10 SAY CustName
  197.  
  198. 5    Memory Variables
  199.  
  200. 5.1    Memory variable names consist of a lowercase data type 
  201. designator (see section 2), followed by a mixedcase description:
  202.  
  203.    cString := "Hello world"
  204.  
  205. 5.2    Underscores should not be used anywhere in a memory variable 
  206. name.  Use mixedcase for names consisting of more than one word:
  207.  
  208.    nTotalCost := Invoices->Cost
  209.  
  210. 5.3    Never give memory variables the same names as database fields.
  211.  
  212. 6    Functions and Procedures
  213.  
  214. 6.1    Clipper function names are uppercase, followed by parentheses:
  215.  
  216.    You can create user-friendly menus with ACHOICE().
  217.  
  218. 6.2    User-defined function and procedure names begin with an 
  219. uppercase letter, followed by lowercase letters as appropriate:
  220.  
  221.    ? Center("Please select a menu option", 80)
  222.  
  223. 6.3    Do not use leading underscores: these are used for Clipper 
  224. internal variable and function names.  Underscores should not be used 
  225. anywhere in a function or procedure name.  Use mixedcase for names 
  226. consisting of more than one word:
  227.  
  228.    YesOrNo("Do you wish to continue?", 10, 10)
  229.  
  230. 6.4    When parameters are specified as part of a function 
  231. declaration, a space is placed inside each parenthesis:
  232.  
  233.    FUNCTION SayInBox( cMessage, cColor )
  234.  
  235. 6.5    The RETURN statement at the end of a function or procedure is 
  236. indented 1 tab (see example in section 15).
  237.  
  238. 6.6    If a subroutine does not return a value, it should be declared 
  239. as a PROCEDURE.  A routine that returns a value should be declared as a 
  240. function.  (Note that calls to both functions and procedures can occur 
  241. in the middle of a line with arguments listed in parentheses.)
  242.  
  243. 6.7    The return value of a function is enclosed in parentheses:
  244.  
  245.    RETURN (cRetValue)
  246.  
  247. 6.8    Wherever possible, variables referenced by a function or 
  248. procedure should be passed as parameters.
  249.  
  250. 7    Preprocessor Directives
  251.  
  252. 7.1    Preprocessor directives are lowercase and are preceded by a "#" 
  253. sign:
  254.  
  255.    #include "Inkey.ch"
  256.  
  257. 7.2    Pseudo-function names follow the same conventions as 
  258. user-defined function and procedure names (see section 6).
  259.  
  260. 7.3    Manifest constants are uppercase:
  261.  
  262.    #define ESCAPE 27
  263.    IF LASTKEY() == ESCAPE
  264.  
  265. 7.4    A blank line should be placed before and after #if...#endif 
  266. directives:
  267.  
  268.    @ 2,10 SAY "ACME Stock Control System"
  269.  
  270.    #if PASSWORD
  271.     <Ask user for password>
  272.    #endif
  273.  
  274.    MainMenu()
  275.  
  276. 8    Standard Classes
  277.  
  278. 8.1    Class names follow the same conventions as user-defined 
  279. function and procedure names (see section 6).
  280.  
  281. 8.2    Instance variable names begin with a lowercase letter, and 
  282. include uppercase letters wherever necessary to indicate new words:
  283.  
  284.    oError:canDefault := .T.
  285.  
  286. 8.3    Method names follow the same convention as instance variable 
  287. names (see above):
  288.  
  289.    oBrowse:pageUp()
  290.  
  291. 8.4    When referring to a class method in text, you must also specify 
  292. the class name:
  293.  
  294.    To reposition the data source to bottom-of-file, use the 
  295.    TBrowse:goBottom() method.
  296.  
  297. 9    Spaces
  298.  
  299. 9.1    Whenever a list of two or more items is used, a space is placed 
  300. after each comma separator:
  301.  
  302.    MyFunc(nChoice, 10, 20, .T.)
  303.  
  304. 9.2    NEVER use spaces to indent code; use tabs instead (see section 
  305. 15).
  306.  
  307. 9.3    When parameters are specified as part of a function 
  308. declaration, a space is placed inside each parenthesis:
  309.  
  310.    FUNCTION SayInBox( cMessage, cColor )
  311.  
  312. 9.4    A space is placed on either side of each binary operator:
  313.  
  314.    nTotal := nSubTotal + nNewCost
  315.  
  316. 10    Declarations
  317.  
  318. 10.1    Each variable is declared separately on its own line:
  319.  
  320.    LOCAL nSomeNum
  321.    LOCAL cString := ""
  322.  
  323. 11    Logicals
  324.  
  325. 11.1    Logical values are referred to in text as follows:
  326.  
  327.    true (.T.)
  328.    false (.F.)
  329.  
  330. The terms "true" and "false" are all lowercase unless they appear at 
  331. the beginning of a sentence, and are followed by the code form of the 
  332. logical value enclosed in parentheses.
  333.  
  334. 12    Operators
  335.  
  336. 12.1    The in-line assignment operator (:=) is used for assignments in 
  337. all Clipper 5.0 code:
  338.  
  339.    lContinue := .T.
  340.  
  341. 12.2    The == operator is used for exact equality tests in all Clipper 
  342. 5.0 code:
  343.  
  344.    lDuplicate := (CustFile->CustName == cCustName)
  345.  
  346. 13    Tabs
  347.  
  348. 13.1      Fixed tabs are at three-space intervals.  This does not mean 
  349. that a tab always expands to 3 spaces.
  350.  
  351. 13.2    Tabs are always used to indent code.
  352.  
  353. 13.3    When placing an in-line comment in your code, use one tab 
  354. between the end of code, and the beginning of the comment.  No other 
  355. intervening white space should exist.  (for the purpose of this 
  356. example, tabs are shown as <tab>):
  357.  
  358.    IF nTabs > 1<tab>// Only 1 tab
  359.    <tab>.
  360.    <tab>. <statements>
  361.    <tab>.
  362.    ENDIF
  363.  
  364. See also section 15 (Indentation) and 17 (Comments).
  365.  
  366. 14    Missing Code
  367.  
  368. 14.1    The fact that code is missing from an example is indicated by a 
  369. line containing a period, followed by a line containing a period and 
  370. "<statements>," followed by a line containing a period.  The lines are 
  371. indented as though they contained code (see section 15):
  372.  
  373.    IF nNumber == 0
  374.     .
  375.     . <statements>
  376.     .
  377.    ENDIF
  378.  
  379. 15    Indentation
  380.  
  381. 15.1    Tabs are used for all indentation. DO NOT uses spaces: it makes 
  382. layout extremely difficult.
  383.  
  384. 15.2    Control structures and the code within functions and procedures 
  385. are indented 1 tab.  The same is true of a function or procedure's 
  386. RETURN statement.  Clipper control structures include BEGIN 
  387. SEQUENCE...END, DO CASE...ENDCASE, DO WHILE...ENDDO, EXIT, LOOP, 
  388. FOR...NEXT, and IF...ENDIF:
  389.  
  390.    PROCEDURE SaySomething
  391.     DO WHILE .T.
  392.         IF nTotal< 50
  393.             ? "Less than 50"
  394.         ELSEIF nTotal == 50
  395.             ? "Equal to 50"
  396.         ELSE
  397.             ? "Greater than 50""
  398.         ENDIF
  399.     ENDDO
  400.     RETURN
  401.  
  402. 15.3    CASE statements in a DO CASE...ENDCASE structure are aligned 
  403. with the "DO CASE:"
  404.  
  405.    DO CASE
  406.    CASE nChoice == 1
  407.     .
  408.     . <statements>
  409.     .
  410.    ENDCASE
  411.  
  412. 15.4    Do not use abbreviations of control structures, such as WHILE 
  413. for DO WHILE and END for ENDIF or ENDDO.  Always type the entire word.
  414.  
  415. 16    Line Continuation
  416.  
  417. 16.1    When a line of code reaches column 60 (or at the previous 
  418. logical break), interrupt the code with a semicolon and continue on the 
  419. next line.  Indent the line by one tab to indicate a continuation:
  420.  
  421.    SET FILTER TO CustFile->Name == "Jim Bowie";
  422.     .AND. CustFile->State == "CA"
  423.  
  424. 16.2    To continue a character string, end the first line with a 
  425. quotation mark and place the remainder on the next line.  Indent the 
  426. line to indicate a continuation:
  427.  
  428.    @ 10,10 SAY "The lazy brown fox tripped over" + ;
  429.     "the broken branch."
  430.  
  431. 17    Comments
  432.  
  433. 17.1    Comments begin with a capital letter, but have no period:
  434.  
  435.    // Just like a sentence, but no period
  436.  
  437. 17.2    For long comments spanning several lines, use the following:
  438.  
  439.    * For Summer '87 code, put one of these at the start of each * line
  440.  
  441.    /* This type of Clipper 5.0 comment can be as large as necessary.  
  442.       Everything bound between the delimiters will be ignored by the 
  443.       preprocessor 
  444.    */
  445.  
  446. // Or you can use the double-slash (//) at the beginning of
  447. // each line for large comments blocks.
  448.  
  449. 17.3    For single-line comments, use the following // rather than *:
  450.  
  451.    // This is a single-line comment in Clipper 5.0
  452.  
  453. 17.4    For in-line comments, use // rather than &&:
  454.  
  455.    USE Customer    // An in-line comment in Clipper 5.0
  456.  
  457. 17.5    Do not use in-line comments for large comment blocks.  Comment 
  458. "paragraphs" should be formatted according to rule 17.2.  If an in-line 
  459. comment wraps beyond the 60th column, consider placing it above the 
  460. code on a separate line at the current indent level.
  461.  
  462.    .                   // Don't make a comment
  463.    .<statements>       // paragraph with aligned
  464.    .                   // in-line comments
  465.  
  466.    // Make your long in-line comments like this...
  467.    .
  468.    .<statements>
  469.    .
  470.    /* ...or, like this.  But, don't place tabs inside your
  471.    comments. */
  472.  
  473.  
  474.  
  475.